package com.ssm.platform.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ssm.platform.pojo.domain.UsersDo;
import com.ssm.platform.pojo.param.UsersParam;
import com.ssm.platform.pojo.query.UsersQuery;
import com.ssm.platform.pojo.vo.UsersVo;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.validation.annotation.Validated;

import javax.validation.groups.Default;
import java.util.Set;

import static com.ssm.basis.service.constant.CacheNameConstant.USER_PAGE_LIST;
import static com.ssm.basis.service.constant.CacheNameConstant.USER_SAVE;

@Validated(Default.class)
public interface IUsersService extends IService<UsersDo> {
    /**
     * @see CachePut 执行方法体，将结果缓存起来
     */
    @CachePut(cacheNames = USER_SAVE, key = "#param.username.concat(#param.identityCardNo)")
    UsersVo post(UsersParam param);

    /**
     * @see CacheEvict 同时移除缓存中的数据，beforeInvocation：先移除缓存，allEntries：移除所有(cacheNames)
     * T(String).valueOf(#name).concat('-').concat(#password)
     */
    @CacheEvict(cacheNames = USER_SAVE, key = "#root.methodName", beforeInvocation = true, allEntries = true)
    Boolean delete(Set<String> usernames);

    /**
     * @see CachePut 执行方法体，将结果缓存起来
     */
    @CachePut(cacheNames = USER_SAVE, key = "#param.username.concat(#param.identityCardNo)")
    UsersVo put(UsersParam param);

    /**
     * @see Cacheable 查找缓存，有就返回，没有就执行方法体，将结果缓存起来
     */
    @Cacheable(cacheNames = {USER_PAGE_LIST}, key = "T(String).valueOf(#query.current).concat(T(String).valueOf(#query.size))")
    IPage<UsersVo> get(UsersQuery query);

    byte[] export(UsersQuery query);
}